package core.sub;

import java.util.ArrayList;
import java.util.List;

import core.obj.Object;
import core.obj.Paycheck;
import core.obj.Resume;

public class Contractor implements Subject {

	private String id;
	private Resume resume = null;	// resume of the contractor
	private List<Paycheck> paychecks = null;

	public void setID(String id){
		this.id = id;
	}
	
	public String getID() {
		return id;
	}

	public boolean equals(java.lang.Object obj) {
		if(obj instanceof Contractor){
			Contractor C = (Contractor)obj;
			if(C.getID().equals(id)) {
				return true;
			}
		}
		return false;
	}

	public void setResume(Resume resume) {
		this.resume = resume;
	}

	public Resume getResume() {
		return resume;
	}

	public void setPaychecks(List<Paycheck> paychecks) {
		this.paychecks = paychecks;
	}

	public List<Paycheck> getPaychecks() {
		return paychecks;
	}
	
	public void addPaycheck(Paycheck p) {
		if(p != null) {
			if(paychecks == null)
				paychecks = new ArrayList<Paycheck>();
			paychecks.add(p);
		}
	}

	@Override
	public Object findObject(String objID) {
		if(resume != null) {
			if(resume.getID().equals(objID)) {
				return resume;
			}
		}
		if(paychecks != null) {
			for(Paycheck p:paychecks) {
				if(p.getID().equals(objID))
					return p;
			}
		}
		return null;
	}
	
}